﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Devices;

namespace WPKeyboard
{
    public static class Helpers
    {
        public static void ShowSMSDialog(string message, string phoneNumber)
        {
            SmsComposeTask task = new SmsComposeTask();
            task.Body = message;
            task.To = phoneNumber;
            task.Show();
        }


        public static void ShowEmailDialog(string message, string email)
        {
            EmailComposeTask task = new EmailComposeTask();
            task.Body = message;
            task.To = email;
            task.Show();
        }

        public enum VibrationMode
        {
            Soft,
            Medium,
            Hard
        }

        public static void Vibrate(VibrationMode pMode)
        {
            TimeSpan ts;

            switch (pMode)
            {
                case VibrationMode.Soft:
                    ts = new TimeSpan(100000);
                    break;
                case VibrationMode.Medium:
                    ts = new TimeSpan(200000);
                    break;
                case VibrationMode.Hard:
                    ts = new TimeSpan(500000);
                    break;
                default:
                    ts = new TimeSpan(100000);
                    break;
            }
            //VibrateController.Default.Start(new TimeSpan();
            VibrateController.Default.Start(ts);
        }

        public enum ClickEffect 
	    {
            CharacterEffect,
            SpaceBarEffect,
            DeleteEffect
	    }

        private const string constCharacterEffect = @"sounds/KbdKeyTap.wav";
        private const string constSpaceBarEffect = @"sounds/KbdSpacebar.wav";
        private const string constDeleteEffect = @"sounds/KbdFunction.wav";

        public static void PlaySound(ClickEffect pEfect)
        {
            switch (pEfect)
            {
                case ClickEffect.CharacterEffect:
                    PlaySound(constCharacterEffect);
                    break;
                case ClickEffect.SpaceBarEffect:
                    PlaySound(constSpaceBarEffect);
                    break;
                case ClickEffect.DeleteEffect:
                    PlaySound(constDeleteEffect);
                    break;
                default:
                    PlaySound(constCharacterEffect);
                    break;
            }
        }

        private static void PlaySound(string path)
        {
            try
            {
                if (!string.IsNullOrEmpty(path))
                {
                    using (var stream = TitleContainer.OpenStream(path))
                    {
                        if (stream != null)
                        {
                            var effect = SoundEffect.FromStream(stream);
                            FrameworkDispatcher.Update();
                            effect.Play();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                
            }
        }

    }
}
